/*
 * KamusKSoap.java
 *
 * Created on August 13, 2008, 11:24 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.kamus.iwic.main;

import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;

/**
 *
 * @author mamat-dev
 */
public class KamusKSoap {
    
    /** Creates a new instance of KamusKSoap */
    public KamusKSoap() {
        
    }
    
    public String getKamusWs(String kata) throws IOException {
        
        SoapObject client = new SoapObject("urn:MKamus","getKamusEngIndo");
        client.addProperty("kata", kata);
        HttpTransport ht = new HttpTransport("http://mamat.amikom.ac.id/mkamus/mkamusws.php");
       // Creating the Soap Envelope
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = client;

        // Call the WebService

        try {
            ht.call("getKamusEngIndo", envelope);
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (XmlPullParserException ex) {
            ex.printStackTrace();
        }
        // Format the Result
        String result = null;
        try {
            result = envelope.getResponse().toString();
        } catch (SoapFault ex) {
            ex.printStackTrace();
        }
        return result;

    }
    
}
